package org.example.demo3;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;


/**
 * @author Gong.Yang
 */
@Slf4j
public class Demo {
    static class Target{
        public void foo(){
            log.info("Im target foo");
        }
        public void boo(){
            log.info("Im target boo");
        }
    }

    public static void main(String[] args) {
//        Target target = new Target();

        Target proxy = (Target) Enhancer.create(Target.class,
                (MethodInterceptor) (obj, method, args1, methodProxy) -> {

                    log.info("proxy method: {}", method.getName());
                    log.info("proxy before");
//                    Object result = methodProxy.invoke(target, args1);
                    Object result = methodProxy.invokeSuper(obj, args1);
                    log.info("proxy after");
                    return result;
                });

        proxy.foo();
    }
}
